/*
 * Copyright 2011 J. Auer, J. Andert, F.-J. Jendrusch, U. Celebi
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package de.fuberlin.replication.test.library;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Vector;

import de.fuberlin.replication.application.Synchronizable;
import de.fuberlin.replication.library.Metadata;
import de.fuberlin.replication.library.Subset;
import de.fuberlin.replication.library.VectorSets;
import de.fuberlin.replication.storage.MetadataDAO;
import de.fuberlin.replication.storage.SubsetDAO;
/**
 * Proxy for testing the private Methods of the VectorSet Class
 */
public class VectorSetsProxy {

	public static Synchronizable APP;
	
	public VectorSetsProxy (Synchronizable app){
		VectorSetsProxy.APP =app;
	}

	public  Subset containsObject(Vector<Subset[]> set, String object){
		Method m;
		try {
			m = VectorSets.class.getDeclaredMethod("containsObject",Vector.class,String.class);
	        m.setAccessible(true);
	        return (Subset)m.invoke(new VectorSets(APP), set,object);
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public static Subset containsObject(SubsetDAO subsetDAO, MetadataDAO metadataDAO, String objectName) {
		Method m;
		try {
			m = VectorSets.class.getDeclaredMethod("containsObject",SubsetDAO.class, MetadataDAO.class,String.class);
	        m.setAccessible(true);
	        return (Subset)m.invoke(new VectorSets(APP), subsetDAO,metadataDAO,objectName);
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public static boolean containsVersion(Vector<Subset> set, Metadata object){
		Method m;
		try {
			m = VectorSets.class.getDeclaredMethod("containsVersion",Vector.class,Metadata.class);
	        m.setAccessible(true);
	        return (Boolean) m.invoke(new VectorSets(APP), set,object);
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
	
	public boolean request() {
		Method m;
		try {
			m = VectorSets.class.getDeclaredMethod("request");
	        m.setAccessible(true);
	        return (Boolean) m.invoke(new VectorSets(APP));
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
	
	public  boolean serve() throws IOException, ClassNotFoundException{
		Method m;
		try {
			m = VectorSets.class.getDeclaredMethod("serve");
	        m.setAccessible(true);
	        return (Boolean) m.invoke(new VectorSets(APP));
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
	
	@SuppressWarnings("unchecked")
	public  Vector<Subset> receiveKnowledge() throws IOException, ClassNotFoundException{
		Method m;
		try {
			m = VectorSets.class.getDeclaredMethod("receiveKnowledge");
	        m.setAccessible(true);
	        return (Vector<Subset>) m.invoke(new VectorSets(APP));
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public  boolean sendKnowledge() throws IOException{
		Method m;
		try {
			m = VectorSets.class.getDeclaredMethod("sendKnowledge");
	        m.setAccessible(true);
	        return (Boolean) m.invoke(new VectorSets(APP));
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
	
	
	public void sendRelevantSets(Vector<Subset> remoteSet) throws IOException{
		Method m;
		try {
			m = VectorSets.class.getDeclaredMethod("sendRelevantSets",Vector.class);
	        m.setAccessible(true);
	        m.invoke(new VectorSets(APP),remoteSet);
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void receiveUpdates() throws IOException{
		Method m;
		try {
			m = VectorSets.class.getDeclaredMethod("receiveUpdates");
	        m.setAccessible(true);
	        m.invoke(new VectorSets(APP));
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void union(){
		Method m;
		try {
			m = VectorSets.class.getDeclaredMethod("union");
	        m.setAccessible(true);
	        m.invoke(new VectorSets(APP));
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	public void merge(Subset localSet, Subset remoteSet, Metadata remoteObject, Object remoteData){
		Method m;
		try {
			m = VectorSets.class.getDeclaredMethod("merge",Subset.class,Subset.class,Metadata.class,Object.class);
	        m.setAccessible(true);
	        m.invoke(new VectorSets(APP),localSet,remoteSet,remoteObject,remoteData);
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public  Subset[] split(Subset localSet, Metadata remoteObject){
		Method m;
		try {
			m = VectorSets.class.getDeclaredMethod("split",Subset.class,Metadata.class);
	        m.setAccessible(true);
	        return (Subset[])m.invoke(new VectorSets(APP),localSet,remoteObject);
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public  void subsetFromNewObject(Subset remoteSet, Metadata remoteObject, Object remoteData){
		Method m;
		try {
			m = VectorSets.class.getDeclaredMethod("subsetFromNewObject",Subset.class,Metadata.class,Object.class);
	        m.setAccessible(true);
	        m.invoke(new VectorSets(APP),remoteSet,remoteObject,remoteData);
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}